package leetcode.math;

import java.util.LinkedList;
import java.util.List;

/**
 * https://leetcode-cn.com/problems/pascals-triangle/
 *
 * @author mazouri
 * @create 2021-09-26 22:33
 */
public class _118_generate {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> res = new LinkedList<>();
        for (int i = 0; i < numRows; i++) {
            LinkedList<Integer> level = new LinkedList<>();
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    level.add(1);
                } else {
                    level.add(res.get(i - 1).get(j - 1) + res.get(i - 1).get(j));
                }
            }
            res.add(level);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(new _118_generate().generate(4));
    }
}
